#include<iostream>
using namespace std;
typedef long long ll;

ll quickpow(ll a,ll b,ll p)
{
	ll result=1;
	while(b)
	{
		if(b&1) result=(result*a)%p;
		b>>=1;
		a=(a*a)%p;
	}
	return result;
}
int main()
{
	ll a,b,p;cin>>a>>b>>p;

	printf("%lld^%lld mod %lld=%lld\n",a,b,p,quickpow(a,b,p));
}